
import 'package:flutter_ahj_app/app/yhpc/YhpcApiRequest.dart';
import 'package:flutter_ahj_app/base/basewidget/model/BaseModel.dart';
import 'package:rxdart/rxdart.dart';

class YhpcModel extends BaseModel {
  // 部门数据
  BehaviorSubject<Map> _buMenDataObservable;
  Stream<Map> get getBuMenDataStream => _buMenDataObservable.stream;
  getBuMenData(String orgName) {
    _buMenDataObservable =  BehaviorSubject();
    YhpcApiRequest.buMenApi(orgName).listen((result){
      _buMenDataObservable.add(result);
    },onError: (e){
      _buMenDataObservable.add(null);
      errorData.add(e);
    });
  }

  // 排查类型
  BehaviorSubject<Map> _pclxObservable;
  Stream<Map> get getPclxDataStream => _pclxObservable.stream;
  getPclx() {
    _pclxObservable =  BehaviorSubject();
    YhpcApiRequest.pclxApi().listen((result){
      _pclxObservable.add(result);
    },onError: (e){
      _pclxObservable.add(null);
      errorData.add(e);
    });
  }

  // 人员
  BehaviorSubject<Map> _personObservable;
  Stream<Map> get getPersonDataStream => _personObservable.stream;
  getPerson(var map) {
    _personObservable =  BehaviorSubject();
    YhpcApiRequest.personApi(map).listen((result){
      _personObservable.add(result);
    },onError: (e){
      _personObservable.add(null);
      errorData.add(e);
    });
  }

  //排查对象
  BehaviorSubject<Map> _pcnrObservable;
  Stream<Map> get getPcnrStream => _pcnrObservable.stream;
  getPcnr(var map) {
    _pcnrObservable =  BehaviorSubject();
    YhpcApiRequest.pcnrApi(map).listen((result){
      _pcnrObservable.add(result);
    },onError: (e){
      _pcnrObservable.add(null);
      errorData.add(e);
    });
  }

  //排查内容
  BehaviorSubject<Map> _pcnrDataObservable;
  Stream<Map> get getPcnrDataStream => _pcnrDataObservable.stream;
  getPcnrData(var map) {
    _pcnrDataObservable =  BehaviorSubject();
    YhpcApiRequest.pcnrDataApi(map).listen((result){
      _pcnrDataObservable.add(result);
    },onError: (e){
      _pcnrDataObservable.add(null);
      errorData.add(e);
    });
  }

  //提交任务
  BehaviorSubject<Map> _submitRwObservable;
  Stream<Map> get getYhlbDataStream => _submitRwObservable.stream;
  getYhlb() {
    _submitRwObservable =  BehaviorSubject();
    YhpcApiRequest.yhlbApi().listen((result){
      _submitRwObservable.add(result);
    },onError: (e){
      _submitRwObservable.add(null);
      errorData.add(e);
    });
  }

  //隐患类别
  BehaviorSubject<Map> _getYhlbObservable;
  Stream<Map> get submitRwStream => _getYhlbObservable.stream;
  submitRw(var map) {
    _getYhlbObservable =  BehaviorSubject();
    YhpcApiRequest.submitRwApi(map).listen((result){
      _getYhlbObservable.add(result);
    },onError: (e){
      _getYhlbObservable.add(null);
      errorData.add(null);
    });
  }

  //隐患登记
  BehaviorSubject<Map> _yhdjObservable;
  Stream<Map> get yhdjDataStream => _yhdjObservable.stream;
  yhdj(var map) {
    _yhdjObservable =  BehaviorSubject();
    YhpcApiRequest.yhdjApi(map).listen((result){
      _yhdjObservable.add(result);
      },onError: (e){
        _yhdjObservable.add(null);
      errorData.add(null);
    });
  }

  //隐患核查
  BehaviorSubject<Map> _yhhcObservable;
  Stream<Map> get yhhcDataStream => _yhhcObservable.stream;
  yhhc(var map) {
    _yhhcObservable =  BehaviorSubject();
    YhpcApiRequest.yhhcApi(map).listen((result){
      _yhhcObservable.add(result);
    },onError: (e){
      _yhhcObservable.add(null);
    });
  }

  //隐患退回
  BehaviorSubject<Map> _yhthObservable;
  Stream<Map> get yhthDataStream => _yhthObservable.stream;
  yhth(var map) {
    _yhthObservable =  BehaviorSubject();
    YhpcApiRequest.yhthApi(map).listen((result){
      _yhthObservable.add(result);
    },onError: (e){
      _yhthObservable.add(null);
    });
  }

  //隐患整改
  BehaviorSubject<Map> _yhzgObservable;
  Stream<Map> get yhzgDataStream => _yhzgObservable.stream;
  yhzg(var map) {
    _yhzgObservable =  BehaviorSubject();
    YhpcApiRequest.yhzgApi(map).listen((result){
      _yhzgObservable.add(result);
    },onError: (e){
      _yhzgObservable.add(null);
    });
  }
  //隐患验收
  BehaviorSubject<Map> _yhysObservable;
  Stream<Map> get yhysDataStream => _yhysObservable.stream;
  yhys(var map) {
    _yhysObservable =  BehaviorSubject();
    YhpcApiRequest.yhysApi(map).listen((result){
      _yhysObservable.add(result);
    },onError: (e){
      _yhysObservable.add(null);
    });
  }

  //隐患判定
  BehaviorSubject<Map> _yhpdObservable;
  Stream<Map> get yhpdDataStream => _yhpdObservable.stream;
  yhpd(var map) {
    _yhpdObservable =  BehaviorSubject();
    YhpcApiRequest.yhpdApi(map).listen((result){
      _yhpdObservable.add(result);
    },onError: (e){
      _yhpdObservable.add(null);
    });
  }

  //隐患上报
  BehaviorSubject<Map> _yhsbObservable;
  Stream<Map> get yhsbDataStream => _yhsbObservable.stream;
  yhsb(var map) {
    _yhsbObservable =  BehaviorSubject();
    YhpcApiRequest.yhsbApi(map).listen((result){
      _yhsbObservable.add(result);
    },onError: (e){
      _yhsbObservable.add(null);
    });
  }

  //隐患治理列表
  BehaviorSubject<Map> _yhzlDataObservable;
  Stream<Map> get getYhzlListDataStream => _yhzlDataObservable.stream;
  getYhzlListData(var map) {
    _yhzlDataObservable =  BehaviorSubject();
    YhpcApiRequest.yhzlListApi(map).listen((result){
      _yhzlDataObservable.add(result);
    },onError: (e){
      _yhzlDataObservable.add(null);
      errorData.add(e);
    });
  }


  //隐患治理详情
  BehaviorSubject<Map> _yhzlListDetailObservable;
  Stream<Map> get yhzlListDetailStream => _yhzlListDetailObservable.stream;
  yhzlListDetail(String id) {
    _yhzlListDetailObservable =  BehaviorSubject();
    YhpcApiRequest.yhzlListDetailApi(id).listen((result){
      _yhzlListDetailObservable.add(result);
    },onError: (e){
      _yhzlListDetailObservable.add(null);
      errorData.add(e);
    });
  }

  //隐患治理详情
  BehaviorSubject<Map> _yhzlDetailModuleObservable;
  Stream<Map> get yhzlListDetailModuleStream => _yhzlDetailModuleObservable.stream;
  yhzlDetailModule(String id) {
    _yhzlDetailModuleObservable =  BehaviorSubject();
    YhpcApiRequest.yhzlDetailModuleApi(id).listen((result){
      _yhzlDetailModuleObservable.add(result);
    },onError: (e){
      _yhzlDetailModuleObservable.add(null);
      errorData.add(e);
    });
  }

  @override
  void dispose() {
    super.dispose();
    if (_buMenDataObservable != null) _buMenDataObservable.close();
    if (_pclxObservable != null) _pclxObservable.close();
    if (_personObservable != null) _personObservable.close();
    if (_pcnrObservable != null) _pcnrObservable.close();
    if (_pcnrDataObservable != null) _pcnrDataObservable.close();
    if (_submitRwObservable != null) _submitRwObservable.close();
    if (_getYhlbObservable != null) _getYhlbObservable.close();
    if (_yhdjObservable != null) _yhdjObservable.close();
    if (_yhzlDataObservable != null) _yhzlDataObservable.close();
    if (_yhzlListDetailObservable != null) _yhzlListDetailObservable.close();
    if (_yhzlDetailModuleObservable != null) _yhzlDetailModuleObservable.close();
    if (_yhhcObservable != null) _yhhcObservable.close();
    if (_yhthObservable != null) _yhthObservable.close();
    if (_yhzgObservable != null) _yhzgObservable.close();
    if (_yhysObservable != null) _yhysObservable.close();
    if (_yhpdObservable != null) _yhpdObservable.close();

  }
}
